<template>
  <el-form
    ref="temp"
    :rules="rules"
    :model="temp"
    label-position="left"
    label-width="110px"
    style="width: 90%; margin-left:50px;"
  >
    <el-form-item label="公司名称" prop="name">
      <el-input v-model="temp.name"/>
    </el-form-item>
    <el-form-item label="电话" prop="phone">
      <el-input v-model="temp.phone"/>
    </el-form-item>
    <el-form-item label="身份证号码" prop="idCard">
      <el-input v-model="temp.idCard"/>
    </el-form-item>
    <el-form-item label="用户类型" prop="type">
      <el-select v-model="temp.type" class="filter-item">
        <el-option v-for="item in roleOptions" :label="item.value" :value="item.id"/>
      </el-select>
    </el-form-item>
    <el-form-item label="用户状态" prop="type">
      <el-select v-model="temp.state" class="filter-item">
        <el-option v-for="item in stateOptions" :label="item.value" :value="item.id"/>
      </el-select>
    </el-form-item>
    <el-row :gutter="30">
      <el-col :span="10">
        <el-form-item label="身份证" prop="licensePic" style="width:100%">
          <div class="grid-content bg-purple">
            <addImgall :image-url="temp.licensePic" @imgUrl="getImg1(arguments)" id="licensePic"/>
          </div>
        </el-form-item>
      </el-col>
      <el-col :span="10">
        <el-form-item label="营业执照" prop="vehiclelicensePic">
          <div class="grid-content bg-purple">
            <addImgall
              :image-url="temp.vehiclelicensePic "
              @imgUrl="getImg1(arguments)"
              id="vehiclelicensePic"
            />
          </div>
        </el-form-item>
      </el-col>
    </el-row>
    <!-- <el-row :gutter="30">
      <el-col :span="10">
        <el-form-item label="身份证照片" prop="cardPic">
          <div class="grid-content bg-purple">
            <addImgall :image-url="temp.cardPic " @imgUrl="getImg1(arguments)" id="cardPic"/>
          </div>
        </el-form-item>
      </el-col>
      <el-col :span="10">
        <el-form-item label="营运证照片" prop="businessPic">
          <div class="grid-content bg-purple">
            <addImgall
              :image-url="temp.businessPic "
              @imgUrl="getImg1(arguments)"
              id="businessPic"
            />
          </div>
        </el-form-item>
      </el-col> -->
    </el-row>
  </el-form>
</template>
<script>
import { createCooperationm, post } from "@/api/v1";
import addImgall from "@/components/img";

export default {
  name: "addOwner",
  props: ["temp"],
  components: { addImgall },
  data() {
    return {
      rules: {
        name: [{ required: true, message: "请输入姓名", trigger: "change" }],
        phone: [{ required: true, message: "请输入电话", trigger: "change" }],
        idCard: [
          { required: true, message: "请输入身份证号码", trigger: "change" }
        ],
        type: [{ required: true, message: "请选择类型", trigger: "change" }]
        // licensePic: [
        //   { required: true, message: "请上传驾驶证照片", trigger: "change" }
        // ],
        // vehiclelicensePic: [
        //   { required: true, message: "请上传行驶证照片", trigger: "change" }
        // ],
        // cardPic: [
        //   { required: true, message: "请上传身份证照片", trigger: "change" }
        // ],
        // businessPic: [
        //   { required: true, message: "请上传营运证照片", trigger: "change" }
        // ]
      },
      roleOptions: [
        { id: 3, value: "司机" },
        { id: 4, value: "个人货主" },
        { id: 5, value: "企业货主" },
        { id: 6, value: "子账号" },
        { id: 7, value: "车队长" },
        { id: 8, value: "运输公司" },
        { id: 10, value: "挂靠公司" },
        { id: 15, value: "城市代理" }
      ],
      stateOptions: [
        { id: 0, value: "注销" },
        { id: 1, value: "审核中" },
        { id: 2, value: "审核失败" },
        { id: 3, value: "审核成功" },
        { id: 4, value: "未认证" }
      ]
    };
  },
  created() {
    // this.getCityData();
  },

  methods: {
    clearTemp() {
      this.$nextTick(() => {
        this.$refs["temp"].clearValidate();
      });
    },
    getImg1(arguments1) {
      console.log(arguments1);
      console.log(arguments1[1]);
      var value = arguments1[1];
      this.temp[`${value}`] = arguments1[0];
      console.log(this.temp);
    },
    submitForm() {
      this.$refs["temp"].validate(valid => {
        if (valid) {
          console.log(this.temp);
          let url = this.temp.id
            ? this.API.URL.DRIVERS_EDIT
            : this.API.URL.DRIVERS_ADD;
          console.log("url是。。。。" + url);
          post(url, this.temp).then(res => {
            // this.list.unshift(this.temp);
            this.dialogFormVisible = false;
            this.$notify({
              title: "成功",
              message: res.msg,
              type: "success",
              duration: 2000
            });

            this.$parent.$parent.getList();
          });
        }
      });
    }
  }
};
</script>
<style>
.demonstration {
  text-align: center;
}
</style>
